<?php

class Controller_Adm_Action_Charts extends Controller_Admin {
	public  function action_save(){
//		$chart = new Model_Chart($_POST['chart_id']);
//		$chart->set_x_axis($_POST['x_axis']);
//		$chart->set_y_axis($_POST['y_axis']);
//		$chart->set_series_type($_POST['series_type']);
//		$chart->set_best_representation($_POST['best_representation']);
//		if(isset($_POST['store_ids'])){
//			$chart->set_stores(json_encode($_POST['store_ids']));
//		}else $chart->set_stores('[]');
//		if(isset($_POST['channels'])){
//			$chart->set_channels(json_encode($_POST['channels']));
//		}else $chart->set_channels('[]');
//		$chart->set_date_start(Date::get_sql_datetime($_POST['dt_start']));
//		$chart->set_date_end(Date::get_sql_datetime($_POST['dt_end']));
//		$chart->save();
//		Model_Chart::populate_chart_data($chart->get_id());
//		Model_Chart::generate_highchart_data_file($chart->get_id());
//		
//		$this->response->body(Json_View::factory(array("redirect"=>true, "url"=>$this->url_root."adm/charts/show/".$chart->get_id())));
	}
	public function action_save_chart_analysis(){
		$analysis = new Model_Chartanalysis();
		$analysis->set_chart_id($_POST['chart_id']);
		$analysis->set_analysis($_POST['analysis']);
		$analysis->set_user_id(Model_User::get_user()->get_id());
		$analysis->set_date_time(date("Y-m-d H:i:s"));
		$analysis->save();
	}
	public function action_remove_chart_analysis(){
		if(Model_User::logged_in('admin') || Model_User::logged_in('operator')){
			$analysis = new Model_Chartanalysis($_POST['analysis_id']);
			$analysis->remove_all_reviews();
			$analysis->remove();
		}
	}
}